import { useGetRealStorage, useGetTokenStorage } from "../../hooks/useStorage";
import { useLoginStore } from "../../store/modules/login";
import { getCurrentInstance } from "vue";
import { jump } from "./tool";
const Whitelist = ["/pages/index/index", "/pages/my/my"];
import mitt from "mitt";
import { eventBus } from "../../enums/eventBus";
/**
 * @description 跳转页面前的用户登录验证
 * @param {String} to : 要跳转的页面
 * @param {String} mode : 跳转方式 默认:'navigateTo'
 * @param {Boolean} login : 是否验证登录
 * @param {Boolean} open : 打开方式 JumpTypeEnum
 * @param {Object} query : 参数
 * @param {Boolean} real : 是否验证实名认证状态
 */
export const jumpPage = (params) => {
  params = params || {};
  const { login = true, real = false } = params;
  const token = useGetTokenStorage();
  const realStatus = useGetRealStorage();
  // 登录验证
  if (login && !token) {
    uni.$emit(eventBus.login.popup, true, "route 路由登录验证拦截");
  }
  // 实名认证
  else if (real && realStatus == 0) {
    // TODO 跳转实名认证页面
  }
  // 跳页
  else jump(params);
};
